/**
 * date: 2014.10
 * writer: young
 */
var start = false;
var startX = 0; 
var srartY = 0;
var ctx ;

function init() {
	
	document.getElementById("canvas").onmousedown = set;
	document.getElementById("canvas").onmousemove = drawing;
	ctx = document.getElementById("canvas").getContext("2d");
	
}
function colo(){
	var col ="#";
	for(i = 0; i<6; i++){
		var ran = Math.floor(Math.random()*15);
		if(ran == 10){
			col +="a";
		}
		else if(ran == 11){
			col +="b";
		}
		else if(ran == 12){
			col +="c";
		}
		else if(ran == 13){
			col +="d";
		}
		else if(ran == 14){
			col +="e";
		}
		else if(ran == 14){
			col +="f";
		}
		else{
			col +=ran;
		}
	}
	return col;
}
function set(e) {
	
	var lc;
	var lw;
	start = !start;
	startX = e.x-12;
	startY = e.y-12;
	// 선 그리기 시작점 설정
	
	if(start){

		ctx.beginPath();
		ctx.moveTo(startX,startY);
		lc = document.getElementById("linecolor");
		lw = document.getElementById("linewidth");
		
		//ctx.strokeStyle= colo();
		ctx.strokeStyle= colo();
		ctx.lineWidth=lw.value;
	}
	else{
		ctx.closePath();
	}
}
function drawing(e) {
	var resultValue = document.getElementById("result");
	var x = e.x;
	var y = e.y;

	if(start){
		ctx.strokeStyle= colo();
		ctx.lineTo(x,y);
		ctx.stroke();
	}
	resultValue.innerHTML = "x = " + x + "y = " + y;
}
